package edu.nanyang.dao;

import edu.nanyang.domain.StudentInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StudentInfoDao {
    @Select("select * from student_info where student_Num=#{studentNum}")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "student_name",property = "studentName"),
            @Result(column = "student_password",property = "studentPassword"),
            @Result(column = "student_phone",property = "studentPhone"),
            @Result(column = "student_gender",property = "studentGender"),
            @Result(column = "student_num",property = "studentNum"),
            @Result(column = "major_info_id",property = "majorInfoId"),
            @Result(column = "major_info_id",property = "majorInfo",one = @One(select ="edu.nanyang.dao.MajorInfoDao.getById")),
            @Result(column = "class_id",property = "classId"),
            @Result(column = "class_id",property = "classInfo",one = @One(select ="edu.nanyang.dao.ClassInfoDao.getById")),
            @Result(column = "recommend_course",property = "recommendCourse"),
            @Result(column = "total_score",property = "totalScore"),
            @Result(column = "student_province",property = "studentProvince")
    })
    StudentInfo getByStudentNum(int studentNum);



    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "student_name",property = "studentName"),
            @Result(column = "student_password",property = "studentPassword"),
            @Result(column = "student_phone",property = "studentPhone"),
            @Result(column = "student_gender",property = "studentGender"),
            @Result(column = "student_num",property = "studentNum"),
            @Result(column = "major_info_id",property = "majorInfoId"),
            @Result(column = "major_info_id",property = "majorInfo",one = @One(select ="edu.nanyang.dao.MajorInfoDao.getById")),
            @Result(column = "class_id",property = "classId"),
            @Result(column = "class_id",property = "classInfo",one = @One(select ="edu.nanyang.dao.ClassInfoDao.getById")),
            @Result(column = "recommend_course",property = "recommendCourse"),
            @Result(column = "total_score",property = "totalScore"),
            @Result(column = "student_province",property = "studentProvince")
    })
    @Select("select * from student_info")
    List<StudentInfo> findAll();

    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "student_name",property = "studentName"),
            @Result(column = "student_password",property = "studentPassword"),
            @Result(column = "student_phone",property = "studentPhone"),
            @Result(column = "student_gender",property = "studentGender"),
            @Result(column = "student_num",property = "studentNum"),
            @Result(column = "major_info_id",property = "majorInfoId"),
            @Result(column = "major_info_id",property = "majorInfo",one = @One(select ="edu.nanyang.dao.MajorInfoDao.getById")),
            @Result(column = "class_id",property = "classId"),
            @Result(column = "class_id",property = "classInfo",one = @One(select ="edu.nanyang.dao.ClassInfoDao.getById")),
            @Result(column = "recommend_course",property = "recommendCourse"),
            @Result(column = "total_score",property = "totalScore"),
            @Result(column = "student_province",property = "studentProvince")
    })
    @Select("select * from student_info where id=#{id}")
    StudentInfo getById(int id);

    @Insert("insert into student_info(student_num,student_name,student_phone,student_gender,major_info_id,class_id,total_score,student_province,creator,create_time) " +
            "values(#{studentNum},values(#{studentName},values(#{studentPhone},values(#{studentGender},values(#{majorInfoId},values(#{classId},#{totalScore},#{studentProvince},#{creator},now())")
    int add(StudentInfo studentInfo);

    @Delete("delete from student_info where id=#{id}")
    int delete(int id);

    //使用@Update注解指明update方法要执行的SQL
    @Update("update  student_info set student_num=#{studentNum},student_name=#{studentName},student_phone=#{studentPhone},student_gender=#{studentGender},major_info_id=#{majorInfoId},class_id=#{classId},operate_time=now(),total_score=#{totalScore},student_province=#{studentProvince},creator=#{creator} where id=#{id}")
    int update(StudentInfo studentInfo);



    @Update("update student_info set operate_time=now(),class_id=#{classId},total_score=#{totalScore} where student_num=#{studentNum}")
    int updateClass(int classId,int totalScore,int studentNum);



}
